const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const phoneVail=data=>{//手机号验证
	var myreg = /^[1][3456789][0-9]{9}$/;
	if (myreg.test(data)) {
		return false;
	} else {
		return true;
	}
}
const toast=data=>{
	wx.showToast({
	  title:data.title,
	  icon: data.icon || 'none',
	  duration:data.duration || 2000
	})
}
const richText=data=>{
  if(data=='' || !data)return '';
  else {
    let text=data.replace(/\<img/gi,'<img style="width:100%;"');
    let texts=text.replace(/\<p><img/gi,'<p style="font-size:0"><img style="width:100%;"');
    return texts;
  }
}

module.exports = {
  formatTime: formatTime,
  phoneVail:phoneVail,
  toast:toast,
  richText:richText
}
